package com.loves.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.loves.admin.mapper.UserRoleMapper;
import com.loves.admin.model.UserRole;
import com.loves.admin.service.UserRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserRoleServiceImpl implements UserRoleService {

    @Resource
    private UserRoleMapper userRoleMapper;


    @Override
    public List<UserRole> findByUserId(String userId) {
        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserRole::getDeleteFlag,false).eq(UserRole::getUserId,userId);
        return userRoleMapper.selectList(queryWrapper);
    }

    @Override
    public void insert(String userId, String roleId) {
        UserRole userRole = new UserRole.Builder().roleId(roleId).userId(userId).deleteFlag(false).build();
        userRoleMapper.insert(userRole);
    }
}
